<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla view library
jimport('joomla.application.component.view');
 
/**
 * Edit category View
 */
class ShopViewCategory extends JView
{
	/**
	 * Category view display edit method
	 * @return void
	 */
	 protected $item = null;
	function display($tpl = null) 
	{
		$this->addToolBar();
 		$this->item = $this->get('Item');
		
		// Display the template
		parent::display($tpl);
	}
	/**
	 * Setting the toolbar
	 */
	protected function addToolBar() 
	{
		JRequest::setVar('hidemainmenu', true);
		JToolBarHelper::title(JText::_('COM_SHOP_CATEGORY_EDIT_TITLE'),'category');
		JToolBarHelper::save('category.save');
		JToolBarHelper::cancel('categories.cancel','JTOOLBAR_CLOSE');
		JToolBarHelper::media_manager( '/' );
		$document = JFactory::getDocument();
		$document->addStyleDeclaration('.icon-48-category {background-image: url(components/com_shop/images/category48x48.png);}');
		
	}
	protected function homePageArray()
	{	
		$arr = array(
		array('value'=>1,'text'=>'Trang chủ'),
		array('value'=>0,'text'=>'Tắt trang chủ'));
		return $arr;
	}
	protected function getOptions()
	{
		// Initialise variables.
		$options = array();

		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
 		$query->select("t2.id as value,t2.title as text ,t2.level");
		$query->from("#__shop_category t1,#__shop_category t2");
		$query->where('t2.lft BETWEEN t1.lft AND t1.rgt');
		$query->group('t2.id,t2.lft,t2.rgt,t2.title');
		$query->order("t2.lft asc");

		// Get the options.
		$db->setQuery($query);
		$options = $db->loadObjectList();
			// Pad the option text with spaces using depth level as a multiplier.
		for ($i = 0, $n = count($options); $i < $n; $i++)
		{
			// Translate ROOT
			if ($options[$i]->level == 0) {
				$options[$i]->text = JText::_('JGLOBAL_ROOT_PARENT');
			}

			$options[$i]->text = str_repeat('- ',$options[$i]->level).$options[$i]->text;
		}

		// Merge any additional options in the XML definition.
		//$options = array_merge($thgetOptions(), $options);
		return $options;
	}
}